<template>
  <a-drawer
    :title="formInfo.id==undefined?'新增':'修改'"
    :maskClosable="true"
    :width="drawerWidth"
    placement="right"
    :closable="true"
    @close="handleCancel"
    :destroyOnClose="true"
    :visible="visible"
    style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;">
    <a-spin :spinning="confirmLoading">
      <a-form-model
        ref="ruleForm"
        :model="formInfo"
        :label-col="$global.labelCol"
        :wrapper-col="$global.wrapperCol"
      >
          <a-row>
              <a-col :span="12">
                  <a-form-model-item label="学校" prop="schname"  :maxLength="50">
                      <a-input v-model="student.schname" disabled="disabled"/>
                  </a-form-model-item>
              </a-col>
              <a-col :span="12">
                  <a-form-model-item label="姓名" prop="eyeRightData" :maxLength="50">
                      <a-input v-model="student.name" disabled="disabled"/>
                  </a-form-model-item>
              </a-col>
          </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="视力左" prop="eyeLeftData" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.eyeLeftData" placeholder="请输入视力左"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="视力右" prop="eyeRightData" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.eyeRightData" placeholder="请输入视力右"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="矫正视力左" prop="eyeLeftClassData"  :maxLength="50">
              <a-input v-model="formInfo.eyeLeftClassData" placeholder="请输入矫正视力左眼"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="矫正视力右" prop="eyeRightClassData"  :maxLength="50">
              <a-input v-model="formInfo.eyeRightClassData" placeholder="矫正视力右"/>
            </a-form-model-item>
          </a-col>
            </a-row>

                <a-row>
                  <a-col :span="12">
            <a-form-model-item label="色觉" prop="manualSeJue" :rules="$valid.required" :maxLength="50">
              <!--<a-input v-model="formInfo.manualSeJue" placeholder="请输入色觉"/>-->
                <a-select v-model="formInfo.manualSeJue" placeholder="请选择">
                    <a-select-option value="">请选择</a-select-option>
                    <a-select-option
                            v-for="(item) in this.$sysDictOptions('sejue')"
                            :key="item.k"
                            :value="item.k">
                        {{ item.v }}
                    </a-select-option>
                </a-select>
            </a-form-model-item>
          </a-col>

              <a-col :span="12">
            <a-form-model-item label="眼位" prop="manualYanWei" :rules="$valid.required" :maxLength="50">
              <!--<a-input v-model="formInfo.manualYanWei" placeholder="请输入眼位"/>-->
                <a-select v-model="formInfo.manualYanWei" placeholder="请选择">
                    <a-select-option value="">请选择</a-select-option>
                    <a-select-option
                            v-for="(item) in this.$sysDictOptions('yanwei')"
                            :key="item.k"
                            :value="item.k">
                        {{ item.v }}
                    </a-select-option>
                </a-select>
            </a-form-model-item>
          </a-col>
                </a-row>
          <a-row>
                  <a-col :span="12">
            <a-form-model-item label="眼球运动" prop="manualYanQiuYunDong" :rules="$valid.required" :maxLength="50">
              <!--<a-input v-model="formInfo.manualYanQiuYunDong" placeholder="请输入眼球运动"/>-->
                <a-select v-model="formInfo.manualYanQiuYunDong" placeholder="请选择">
                    <a-select-option value="">请选择</a-select-option>
                    <a-select-option
                            v-for="(item) in this.$sysDictOptions('yanqiuyundong')"
                            :key="item.k"
                            :value="item.k">
                        {{ item.v }}
                    </a-select-option>
                </a-select>
            </a-form-model-item>
          </a-col>

              <a-col :span="12">
            <a-form-model-item label="眼睑内翻倒睫" prop="manualYanJianNeiFan" :rules="$valid.required" :maxLength="50">
              <!--<a-input v-model="formInfo.manualYanJianNeiFan" placeholder="请输入眼睑内翻倒睫"/>-->
                <a-select v-model="formInfo.manualYanJianNeiFan" placeholder="请选择">
                    <a-select-option value="">请选择</a-select-option>
                    <a-select-option
                            v-for="(item) in this.$sysDictOptions('yanjianneifan')"
                            :key="item.k"
                            :value="item.k">
                        {{ item.v }}
                    </a-select-option>
                </a-select>
            </a-form-model-item>
          </a-col>
          </a-row>
          <a-row>
                  <a-col :span="12">
            <a-form-model-item label="眼睑肿物" prop="manualYanLianZhongWu" :rules="$valid.required" :maxLength="50">
             <!-- <a-input v-model="formInfo.manualYanLianZhongWu" placeholder="请输入眼睑肿物"/>-->
                <a-select v-model="formInfo.manualYanLianZhongWu" placeholder="请选择">
                    <a-select-option value="">请选择</a-select-option>
                    <a-select-option
                            v-for="(item) in this.$sysDictOptions('yanjianneifan')"
                            :key="item.k"
                            :value="item.k">
                        {{ item.v }}
                    </a-select-option>
                </a-select>
            </a-form-model-item>
          </a-col>

              <a-col :span="12">
            <a-form-model-item label="眼睑上睑下垂" prop="manualYanLianShangLian" :rules="$valid.required" :maxLength="50">
              <!--<a-input v-model="formInfo.manualYanLianShangLian" placeholder="请输入眼睑上睑下垂"/>-->
                <a-select v-model="formInfo.manualYanLianShangLian" placeholder="请选择">
                    <a-select-option value="">请选择</a-select-option>
                    <a-select-option
                            v-for="(item) in this.$sysDictOptions('yanjianneifan')"
                            :key="item.k"
                            :value="item.k">
                        {{ item.v }}
                    </a-select-option>
                </a-select>
            </a-form-model-item>
          </a-col>
          </a-row>
          <a-row>
                  <a-col :span="12">
            <a-form-model-item label="结膜充血" prop="manualJieMoChongXie" :rules="$valid.required" :maxLength="50">
             <!-- <a-input v-model="formInfo.manualJieMoChongXie" placeholder="请输入结膜充血"/>-->
                <a-select v-model="formInfo.manualJieMoChongXie" placeholder="请选择">
                    <a-select-option value="">请选择</a-select-option>
                    <a-select-option
                            v-for="(item) in this.$sysDictOptions('yanjianneifan')"
                            :key="item.k"
                            :value="item.k">
                        {{ item.v }}
                    </a-select-option>
                </a-select>
            </a-form-model-item>
          </a-col>

              <a-col :span="12">
            <a-form-model-item label="结膜充血分泌物" prop="manualJieMoChongXieMiWu" :rules="$valid.required" :maxLength="50">
             <!-- <a-input v-model="formInfo.manualJieMoChongXieMiWu" placeholder="请输入结膜充血分泌物"/>-->
                <a-select v-model="formInfo.manualJieMoChongXieMiWu" placeholder="请选择">
                    <a-select-option value="">请选择</a-select-option>
                    <a-select-option
                            v-for="(item) in this.$sysDictOptions('yanjianneifan')"
                            :key="item.k"
                            :value="item.k">
                        {{ item.v }}
                    </a-select-option>
                </a-select>
            </a-form-model-item>
          </a-col>
                </a-row>
          <a-row>
                  <a-col :span="12">
            <a-form-model-item label="右球镜" prop="yanguangYouQiuJing" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.yanguangYouQiuJing" placeholder="请输入右球镜"/>
            </a-form-model-item>
          </a-col>

              <a-col :span="12">
            <a-form-model-item label="右柱镜" prop="yanguangYouZhuJing" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.yanguangYouZhuJing" placeholder="请输入右柱镜"/>
            </a-form-model-item>
          </a-col>
          </a-row>
          <a-row>
                  <a-col :span="12">
            <a-form-model-item label="右轴位" prop="yanguangYouZhouWei" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.yanguangYouZhouWei" placeholder="请输入右轴位"/>
            </a-form-model-item>
          </a-col>

              <a-col :span="12">
            <a-form-model-item label="左球镜" prop="yanguangZuoQiuJing" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.yanguangZuoQiuJing" placeholder="请输入左球镜"/>
            </a-form-model-item>
          </a-col>
          </a-row>
          <a-row>
                  <a-col :span="12">
            <a-form-model-item label="左柱镜" prop="yanguangZuoZhuJing" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.yanguangZuoZhuJing" placeholder="请输入左柱镜"/>
            </a-form-model-item>
          </a-col>
              <a-col :span="12">
            <a-form-model-item label="左轴位" prop="yanguangZuoZhouWei" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.yanguangZuoZhouWei" placeholder="请输入左轴位"/>
            </a-form-model-item>
          </a-col>
                </a-row>

      </a-form-model>
    </a-spin>
    <div class="drawer-bootom-button">
      <a-popconfirm title="确定放弃编辑？" @confirm="handleCancel" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="confirmLoading">提交</a-button>
    </div>
  </a-drawer>
</template>

<script>
  import moment from 'moment'
  import { getAction, postAction } from '@/api/manage'
  export default {
    name: 'EyeStudentTestRecordEdit',
    components: {
    },
    data () {
      return {
        visible: false,
        confirmLoading: false,
          student:{},
        formInfo: {
          studentId: undefined,
          schid: undefined,
          eyeLeftData: undefined,
          eyeRightData: undefined,
          eyeLeftClassData: undefined,
          eyeRightClassData: undefined,
          createTime: undefined,
          workShilibiaoFlag: undefined,
          workManualFlag: undefined,
          workYanguangFlag: undefined,
          createByShilibiao: undefined,
          createByManual: undefined,
          createByYanguang: undefined,
          dealTimeShilibiao: undefined,
          dealTimeManual: undefined,
          dealTimeYanguang: undefined,
          manualSeJue: undefined,
          manualYanWei: undefined,
          manualYanQiuYunDong: undefined,
          manualYanJianNeiFan: undefined,
          manualYanLianZhongWu: undefined,
          manualYanLianShangLian: undefined,
          manualJieMoChongXie: undefined,
          manualJieMoChongXieMiWu: undefined,
          manualRemark: undefined,
          yanguangYouQiuJing: undefined,
          yanguangYouZhuJing: undefined,
          yanguangYouZhouWei: undefined,
          yanguangZuoQiuJing: undefined,
          yanguangZuoZhuJing: undefined,
          yanguangZuoZhouWei: undefined,
          wx: ''
        },
        drawerWidth: 800,
          addflag:false,
        url: {
          saveInfo: '/system/eyeStudentTestRecord/save',
          getInfo: '/system/eyeStudentTestRecord/info'
        }
      }
    },
    created () {
    },
    methods: {
      add () {
          this.addflag=true;
        this.edit()
      },
      moment,
      edit (record) {
        this.$objToOverride(this.formInfo, record)
        if (this.formInfo.id) {
          getAction(this.url.getInfo, { 'id': record.id }).then(res => {
            this.$nextTick(() => {
              this.formInfo = res.result.data
                this.student = res.result.student
            })
          })
        }
        this.visible = true
      },
        edit1(record){
          console.log('edit1',record)
          this.formInfo.studentId=record.id
            this.formInfo.schid=record.schid
            this.formInfo.gradeId=record.gradeid
            this.formInfo.classId = record.classid
            this.student = record
            console.log(this.formInfo)
            this.visible = true
        },
      // 确定
      handleSubmit () {
          console.log(this.formInfo)
        // 触发表单验证
        this.confirmLoading = true
        this.$refs.ruleForm.validate(valid => {
          console.log(valid)
          if (valid) {
            postAction(this.url.saveInfo, this.formInfo).then(res => {
              this.$message.success(res.content)
              this.$emit('ok', this.formInfo)
              this.close()
            }).finally(() => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      // 关闭
      handleCancel () {
        this.close()
      },
      close () {
        this.$refs.ruleForm.resetFields()
        this.$objToReset(this.formInfo)
          this.addflag = false;
          this.$objToReset(this.student)
        this.$emit('close')
        this.visible = false
      },
      editorOk (val) {
        this.formInfo.content = val
      }
    }
  }
</script>
